package cn.idu.ismik.sample.reflection;

import java.lang.annotation.ElementType;

/**
 * 创建class的方式
 */
public class Test03 {

    public static void main(String[] args) throws ClassNotFoundException {
        Person person = new Student();

        //1. 通过对象获得
        Class c1 = person.getClass();

        //2. forName获得
        Class c2 = Class.forName("cn.idu.ismik.sample.reflection.Student");

        //3. 通过类名.class获得
        Class<Student> c3 = Student.class;

        //4. 基本类型的包装类都有一个TYPE属性
        Class<Integer> cI = Integer.TYPE;

        System.out.println(c1.hashCode());
        System.out.println(c2.hashCode());
        System.out.println(c3.hashCode());
        System.out.println(cI);

        // 获取父类的类型
        System.out.println(c1.getSuperclass());

        //所有类型的class
        System.out.println(Object.class);//对象
        System.out.println(Runnable.class);//接口
        System.out.println(String[].class);//数组
        System.out.println(int[][][].class);
        System.out.println(Deprecated.class);//注解
        System.out.println(ElementType.class);//枚举
        System.out.println(Integer.class);//基本类型
        System.out.println(void.class);//void
        System.out.println(Class.class);//Class

    }
}

class Person {
    public String name;

    public Person() {
    }

    public Person(String name) {
        this.name = name;
    }
}

class Student extends Person {
    public Student() {
        this.name = "学生";
    }
}

class Teacher extends Person {
    public Teacher() {
        this.name = "老师";
    }
}

